package com.relsell.controller;

import java.io.IOException;

import android.content.Context;

import com.relsell.model.ParserImpl;
import com.relsell.model.RecentBassLessonsParserImpl;
import com.relsell.model.RecentBollywoodLessonsParserImpl;
import com.relsell.model.RecentGuitarLessonsParserImpl;
import com.relsell.model.RecentSongLessonsParserImpl;
import com.relsell.utility.ApplicationVars;
import com.relsell.view.phone.RecentBassLessons;

public class DataController implements DataControllerInterface {
	ParserInterface mParserInterface;

	@Override
	public void startProcess(int screen, Context context) {
		String fileName = null;
		String fileURL = null;
		boolean dataNeeded = false;
		boolean fileFound = false;
		if (screen == 0) {
			fileName = "page2_torrins_guitar_lesson.json";
			//fileURL = "http://www.torrins.com/services/lesson/list?parent=0&children=1&id=1";
			fileURL = "http://khottal.com/relsell/torrins_json/";
			fileFound = ApplicationVars.getInstance()
					.isInstructorDataNeededfromServer();
			mParserInterface = new ParserImpl(screen, context);
		} else if (screen == 1) {
			fileName = "page2_torrins_guitar_lesson.json";
			fileURL = "http://www.torrins.com/services/lesson/list?parent=0&children=1&id=1";
			if (ApplicationVars.getInstance().isTestingUrl())  {
			    fileURL = "http://khottal.com/relsell/torrins_json/"+fileName;
			}
			fileFound = ApplicationVars.getInstance()
					.isInstructorDataNeededfromServer();
			mParserInterface = new ParserImpl(screen, context);
		} else if (screen == 4) {
			fileName = "page4_torrins_recent_songs_lesson.json";
			fileURL = "http://www.torrins.com/services/lesson/list?recentSong=1";
			fileFound = ApplicationVars.getInstance()
					.isRecentSongsLessonDataNeededfromServer();
			mParserInterface = new RecentSongLessonsParserImpl(screen, context);
		}else if (screen == 5) {
			fileName = "page5_torrins_recent_bass_lesson.json";
			fileURL = "http://www.torrins.com/services/lesson/list?recentBass=1";
			fileFound = ApplicationVars.getInstance()
					.isRecentSongsLessonDataNeededfromServer();
			mParserInterface = new RecentBassLessonsParserImpl(screen, context);
		}
		else if (screen == 6) {
			fileName = "page6_torrins_recent_guitar_lesson.json";
			fileURL = "http://www.torrins.com/services/lesson/list?recentGuitar=1";
			fileFound = ApplicationVars.getInstance()
					.isRecentSongsLessonDataNeededfromServer();
			mParserInterface = new RecentGuitarLessonsParserImpl(screen, context);
		}
		else if (screen == 7) {
			fileName = "page7_torrins_recent_bollywood_lesson.json";
			fileURL = "http://www.torrins.com/services/lesson/list?recentBollywood=1";
			fileFound = ApplicationVars.getInstance()
					.isRecentBollyWoodLessonDataNeededfromServer();
			mParserInterface = new RecentBollywoodLessonsParserImpl(screen, context);
		}

		try {
			if(!fileFound) {
				dataNeeded = true;
			}
			mParserInterface.startParsingJsonData(context, dataNeeded, fileName,
					fileURL);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
